<?php
	global $SSO, $Security, $AppID, $User, $DB, $GlobalSettings;
	//Check to see if there is a valid session 
	$SessionInfo = $SSO->isValidSession("index.php?action=login", $SSO->getSessionInformation());	
		
	//Check to see if the user has rights to be on LivingWeb
	$PageRights = array('ADMIN', 'USER');
	$UserRoles = $Security->ValidateUser($SessionInfo['username'], $AppID, $PageRights, 1);
	
	//Grab the user info
	$UserInfo = $User->GetUserInfo($SessionInfo['username']);	
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td>
			<?php
				if(isset($_GET['PID']))
				{
					$thePID = $_GET['PID'];
				}
				if(isset($_POST['PID']))
				{
					$thePID = $_POST['PID'];
				}
				if(isset($thePID))
				{
					global $DB;
					$DB->query("SELECT * FROM pages p JOIN ministries m ON p.MinistryID = m.MinistryID JOIN page_content pc ON p.PageID = pc.PageID WHERE p.PageID = '" . $thePID . "'");
					if($row = $DB->fetch_row())
					{
						if(!in_array("ADMIN",$UserRoles))
						{
							$array_of_divs = explode(",",$UserInfo['div_codes']);
							if(trim($UserInfo['div_codes']) == "")
							{
								print '<script>alert(\'You do not have access to any ministries.\nContact your adminsitrator if you believe this to be an error.\');history.back(-1);</script><noscript><span class="T1">You do not have access to any ministries.  Contact your adminsitrator if you believe this to be an error.</span></noscript>';
							}
							elseif(!in_array($row[$GlobalSettings['DivisionElement']],$array_of_divs))
							{
								print '<script>alert(\'You do not have access to this page.\nContact your adminsitrator if you believe this to be an error.\');history.back(-1);</script><noscript><span class="T1">You do not have access to this page.  Contact your adminsitrator if you believe this to be an error.</span></noscript>';
							}
							else
							{
								include('edit_page.php');
							}
						}
						else
						{
							include('edit_page.php');
						}
					}
					else
					{
						print '<script>alert(\'Page ID is not valid.\');history.back(-1);</script><noscript><span class="T1">Page ID is not valid.</span></noscript>';
					}
				}
				else
				{
					print '<script>alert(\'Page ID is not provided.\');history.back(-1);</script><noscript><span class="T1">Page ID is not provided.</span></noscript>';
				}
			?>
		</td>
	</tr>
</table>